import time

from selenium import webdriver
from selenium.webdriver import ActionChains


def f1(browser):
    url = 'https://www.mogu.com/'
    browser.get(url)
    time.sleep(1)
    # 获取网页内容
    html = browser.page_source
    # 获取网址
    current_url = browser.current_url
    print(current_url)
    # sele自带xpath
    imgs = browser.find_elements_by_xpath(
        '//div[@class="cp-lookItem-image text-center lazy-image aspect-fill width-long"]//img')
    print(imgs)
    for img in imgs:
        # 获取节点对应属性
        print(img.get_attribute('src'))
        # 坐标
        # print(img.location)
    # 根据文字获取链接节点
    # a_link = browser.find_element_by_link_text('我的订单')
    # a_link.click()
    # time.sleep(3)
    # 根据部分文字获取链接节点
    # elem = browser.find_elements_by_partial_link_text('订单')
    # for e in elem:
    #     print(e.text)


def f2(browser):
    url = 'https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable'
    browser.get(url)
    time.sleep(1)
    browser.switch_to.frame('iframeResult')  # 切换到iframe内网址
    src_elem = browser.find_element_by_id('draggable')
    dest_elem = browser.find_element_by_id('droppable')
    # 动作链
    action = ActionChains(browser)
    action.drag_and_drop(src_elem, dest_elem)
    action.perform()  # 执行动作
    time.sleep(5)


def main():
    browser = webdriver.Chrome()
    # f1(browser)
    f2(browser)


if __name__ == '__main__':
    main()
